// Tags:
#include <cstdio>
#define id(i, j) ((i - 1) * n + j - 1)

const int N = 6e2 + 5;
int n, len, pot;
long long d;
int e_cnt, heads[N * N], ans[N * N];
bool vis[N * N];

struct Edge {
  int v, nxt;
} e[N * N];

inline int getoriginalid(int x) { return x / n + 1; }

inline void add(int u, int v) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
  // printf("%d %d\n", (u), (v));
}

bool solve(int u) {
  ans[++len] = u;
  vis[u] = true;
  for (int i = heads[u], v; i; i = e[i].nxt) {
    if (!vis[v = e[i].v]) {
      if (solve(v)) return true;
    } else
      return pot = v, true;
  }
  return false;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("speech.in", "r", stdin);
  freopen("speech.out", "w", stdout);
#endif
#endif

  scanf("%d%lld", &n, &d);
  for (int i = 1, tmp; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      scanf("%d", &tmp);
      if (i != j) { add(id(i, j), id(tmp, i)); }
    }
  }
  add(id(1, 1), id(2, 1));
  solve(id(1, 1));
  int line = 0, cir = 0;
  for (int i = 1; i <= len; ++i) {
    if (ans[i] == pot) {
      line = i - 1, cir = len - i + 1;
      break;
    }
  }
  if (d <= line) {
    printf("%d", getoriginalid(ans[d]));
  } else {
    d -= line;
    printf("%d", getoriginalid(ans[line + ((d % cir == 0) ? cir : d % cir)]));
  }
  return 0;
}